#ifndef __LOG_H__
#define __LOG_H__

#include <syslog.h>
#include <libgen.h>
#include <pthread.h>
#include "errorcode.h"
#if 0
#define LOG_ERROR(format, args...)          syslog(LOG_ERR, "%s:%d:%s [ERROR]==>"format, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#define LOG_WARN(format, args...)           syslog(LOG_WARNING, "%s:%d:%s [WARNING]==>"format, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#define LOG_INFOMATION(format, args...)     syslog(LOG_INFO, "%s:%d:%s [INFO]==>"format, basename(__FILE__), __LINE__, __FUNCTION__, ##args)
#endif

#define LOG_ERROR(format, args...)          syslog(LOG_ERR, "%s:%d:%s [TID:%ld][ERROR]==>"format, basename(__FILE__), __LINE__, __FUNCTION__, (ULONG)pthread_self(), ##args)
#define LOG_WARN(format, args...)           syslog(LOG_WARNING, "%s:%d:%s [TID:%ld][WARNING]==>"format, basename(__FILE__), __LINE__, __FUNCTION__, (ULONG)pthread_self(), ##args)
#define LOG_INFOMATION(format, args...)     syslog(LOG_INFO, "%s:%d:%s [TID:%ld][INFO]==>"format, basename(__FILE__), __LINE__, __FUNCTION__, (ULONG)pthread_self(), ##args)

#define LOG_ERROR_RET(ret, format, args...) \
if (ERR_OK != ret) \
{ \
    LOG_ERROR(format, ##args); \
    return ret; \
}

#define LOG_ERROR_NULL_RET(ptr) \
if (NULL == ptr) \
{ \
    LOG_ERROR("pointer null error"); \
    return ERR_NULL_POINTER; \
}

#define LOG_ERROR_CONTINUE(ret, format, args...) \
if (ERR_OK != ret) \
{ \
    LOG_ERROR(format, ##args); \
    continue; \
}

extern void log_init();

#endif
